
if(typeof MsgType == 'undefined'){
  var MsgType = {};
  MsgType.LOGIN_SUCC=1;
  MsgType.LOGIN_NO_USER=2;
  MsgType.LOGIN_WRONG_PASSWORD=3;
  MsgType.REGISTER_SUCC=4;
  MsgType.REGISTER_USER_EXIST=5;
  MsgType.FormatMsg = function(_type){
    return {type:_type}
  };
  
}
var Client = {
		username:null,
		socket:null,
		send:function(action,data){
			Client.socket.emit(action,data);
		},

		login:function(_username,_password){
			var data = {
			            username:_username,
			            password:_password
			            };
      this.send('user_login',data);
		},
    register:function(_username,_password){
    	var data = {
			            username:_username,
			            password:_password
			            };
      this.send('user_register',data);
    },
		chat:function(message){

			this.send('message',data);
		},
		connect:function(){
		},
		receive:function(data){
		},
		disconnect:function(){
			//alert("dis");
		},
    processSysMsg:function(jsonStr){
      //$('#login-btn').text = jsonStr;
      //alert(jsonStr);
      //$('#input-username').value = jsonStr;
      //$('#hmsg').value = jsonStr;
      /*
	  var msgObj = JSON.parse(jsonStr) ;

      var monitorObj = JSON.parse(msgObj.content);
      var msg = "DeviceName:"+monitorObj.DevName+ " DeviceNo:"+ monitorObj.DevNo+" "+monitorObj.MonitorContent+":"+monitorObj.MonitorValue+ " date:"+monitorObj.MonitorDate;
      $('#hmsg').text(msg);//*/
    },
    processMonitorStatus:function(jsonStr){
      //alert(jsonStr);


      
    //alert(jsonStr);
    },
		
		init:function(UpdateStatus){
    
			//this.socket = io.connect('http://192.168.0.105:3000');
			this.socket = io.connect(window.location.host);
			this.socket.on("connect",Client.connect);
			this.socket.on("message",Client.receive);
			this.socket.on("disconnect",Client.disconnect);
			this.socket.on('MonitorUpdate',this.processSysMsg);
      this.socket.on('MonitorStatus',UpdateStatus);
  //  alert('init');
		}
}